package com.uuah.server.config.spring.parsers.collection;

import java.util.Properties;

import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.ParserContext;
import org.w3c.dom.Element;

import com.uuah.server.config.spring.UuahHierarchicalBeanDefinitionParserDelegate;
import com.uuah.server.config.spring.parsers.generic.ChildDefinitionParser;

/**
 * Creates a single Properties object and processes standard Spring sub
 * elements. The properties are injected into the parent object (the enclosing
 * XML element).
 */
public class ChildPropertiesDefinitionParser extends ChildDefinitionParser {

	public ChildPropertiesDefinitionParser(String setterMethod) {
		super(setterMethod, /* clazz */null);
		addBeanFlag(UuahHierarchicalBeanDefinitionParserDelegate.UUAH_NO_RECURSE);
	}

	protected Class getBeanClass(Element element) {
		return PropertiesFactoryBean.class;
	}

	protected void parseChild(Element element, ParserContext parserContext,
			BeanDefinitionBuilder builder) {
		super.parseChild(element, parserContext, builder);
		Properties parsedProps = parserContext.getDelegate().parsePropsElement(
				element);
		builder.addPropertyValue("properties", parsedProps);
	}

}
